<template>
	<view class="orders-page">
		<hsb-core-orders
			:tabList="list"
			:orderList="orderList"
			@load="loadMore"
			@change="change"
			@order="orderPage"
		/>
	</view>
</template>

<script>
import { orderStatusList } from '@/config'
	
export default {
	data () {
		return {
			list: orderStatusList,
			orderList: [],
			type: orderStatusList[0].id,
			pageIndex: 1,
			pageSize: 20,
			pageInfo: {}
		}
	},
	methods: {
		async getOrderList (more = false) {
			uni.showLoading({
				mask: true
			})
			const pageIndex = more ? Number(this.pageIndex) + 1 : 1
			const pageSize = this.pageSize
			const [res] = await this.$apis.getOrderList({
				type: this.type,
				pageIndex,
				pageSize
			})
			uni.hideLoading()
			if (res._errCode === '0') {
				const list = res._data.orderList || []
				this.orderList = more ? this.orderList.concat(list) : list
				this.pageIndex = pageIndex
				this.pageInfo = res._data.pageInfo || {}
			}
		},
		change ({ index }) {
			this.orderList = []
			this.type = orderStatusList[index].id
			this.getOrderList()
		},
		loadMore () {
			if (this.orderList.length >= this.pageInfo.total) return
			this.getOrderList(true)
		},
		orderPage (orderInfo) {
			uni.navigateTo({
				url: `/pages/order/detail/index?orderNum=${orderInfo.orderNum}`
			})
		}
	},
	onShow () {
		this.getOrderList()
	}
}
</script>

<style lang="scss" scoped>
.orders-page {
	height: 100%;
	// 兼容微信小程序
	/deep/ .uv-tabs__wrapper__nav__line {
		bottom: 0;
	}
}
</style>
